package com.easy.work.function.mall;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.work.R;
import com.easy.work.bean.MallGoodsBean;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/12/16.
 * 兑换商品
 */
public class MallListAdapter extends BaseAdapter {

    private Context mCtx;
    List<MallGoodsBean> mallGoodsList = new ArrayList<>();

    public MallListAdapter(Context context, List<MallGoodsBean> mallGoodsList) {
        this.mCtx = context;
        this.mallGoodsList = mallGoodsList;
    }

    @Override
    public int getCount() {
        return mallGoodsList.size();
    }

    @Override
    public Object getItem(int position) {
        return mallGoodsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mCtx).inflate(R.layout.item_mall, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MallGoodsBean bean = mallGoodsList.get(position);
        Picasso.with(mCtx).load(bean.goodsImageX).into(viewHolder.imgGoodsImage);
        viewHolder.tvGoodsName.setText(bean.goodsName);
        viewHolder.tvIntegral.setText(bean.integral + "");
        viewHolder.tvExchangeNum.setText("已兑换" + bean.exchangeNum + "件");

        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.img_goods_image)
        ImageView imgGoodsImage;
        @BindView(R.id.tv_goods_name)
        TextView tvGoodsName;
        @BindView(R.id.tv_integral)
        TextView tvIntegral;
        @BindView(R.id.tv_exchangeNum)
        TextView tvExchangeNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
